package com.rural.bus.model;

import org.json.JSONException;
import org.json.JSONObject;

import com.rural.bus.net.MyHttpUtil;
import com.rural.bus.net.OnNetCallback;
import com.rural.bus.net.Url;

/***
 * 
 * 行程
 * @author majie
 *
 */
public class Railway {
	
	public Order order;
	public int callStatus;
	
	/***
	 * 行程呼叫
	 * @param uid
	 * @param userName
	 * @param startLocation
	 * @param startLongtitude
	 * @param startLatitude
	 * @param endLocation
	 * @param endLatitude
	 * @param endLongtitude
	 * @param takeTime
	 * @param number
	 * @param carType
	 * @param orderType
	 * @param distance
	 * @param mergeId
	 * @param callback
	 */
	public void call(int uid ,String userName,String startLocation,double startLongtitude,
			double startLatitude,String endLocation,double endLatitude,double endLongtitude,
			long takeTime,int number,int carType,int orderType,double distance,int mergeId,String userPhone,String remarks,final OnNetCallback callback){
		MyHttpUtil http=new MyHttpUtil();
		http.addBodyParm("uid", ""+uid);
		http.addBodyParm("userName", userName);
		http.addBodyParm("startLocation", startLocation);
		
		http.addBodyParm("startLongtitude", ""+startLongtitude);
		http.addBodyParm("startLatitude", ""+startLatitude);
		http.addBodyParm("endLocation", endLocation);
		
		http.addBodyParm("endLatitude", ""+endLatitude);
		http.addBodyParm("endLongtitude", ""+endLongtitude);
		http.addBodyParm("takeTime", ""+takeTime);
		
		http.addBodyParm("number", ""+number);
		http.addBodyParm("carType", ""+carType);
		http.addBodyParm("orderType", ""+orderType);
		http.addBodyParm("distance", ""+distance);
		http.addBodyParm("mergeId",""+ mergeId);
		http.addBodyParm("userPhone", userPhone);
		http.addBodyParm("remarks", remarks);
		http.send(Url.call_url, new OnNetCallback() {
			
			@Override
			public void success(JSONObject object) {
			    try {
					Railway.this.order=Order.parse(object.getJSONObject("order"));
					Railway.this.callStatus=object.getInt("callStatus");
				} catch (JSONException e) {
					e.printStackTrace();
				}
				callback.success(object);
			}
			
			@Override
			public void fail(String error) {
				callback.fail(error);
			}
		});
	}
	
	/***
	 * 取消行程
	 * @param uid
	 * @param remarks
	 * @param callback
	 */
	public static void cancel(String uid,int orderId,String remarks,OnNetCallback callback){
		MyHttpUtil http=new MyHttpUtil();
		http.addBodyParm("uid", uid);
		http.addBodyParm("orderId", ""+orderId);
		http.addBodyParm("remarks", remarks);
        http.send(Url.cancel_url, callback);
	}
	
	/***
	 * 价格估计
	 * @param uid
	 * @param takeTime
	 * @param number
	 * @param carType
	 * @param orderType
	 * @param distance
	 * @param mergeId
	 * @param callback
	 */
	public static void check(int uid,long takeTime,int number,int carType,int orderType,double distance,int mergeId,OnNetCallback callback){
		MyHttpUtil http=new MyHttpUtil();
		http.addBodyParm("uid", ""+uid);
		http.addBodyParm("takeTime", ""+takeTime);
		http.addBodyParm("number", ""+number);
		http.addBodyParm("carType", ""+carType);
		http.addBodyParm("orderType", ""+orderType);
		http.addBodyParm("distance", ""+distance);
		http.addBodyParm("mergeId", ""+mergeId);

        http.send(Url.check_url, callback);
	}

}
